import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';

bool turn_on = true;
bool mic_on = false;

int rgbIndex = 0;
String ledNum = '200'; // 存储输入的值

String rgbIndexKey = 'rgbIndexKey';
String ledNumKey = 'ledNumKey';

///主题背景颜色
const Color Color_theme = Color(0xFFD67630);
const Color Color_Line_bg = Color(0xFFB3B3B3);

///键盘色效果
const Color Color_left = Color(0xFF6BCFFB);
const Color Color_right = Color(0xFF2D6EEC);

///子视图背景颜色
const Color Color_Bottom_bg = Color(0xFF404146);
const Color Color_line_view = Color(0xFF4C4C4E);
const Color Color_alert_view = Color(0xFF252934);

const Color Color_btn_hight = Color(0xFFD32C26);
const LinearGradient localGradient = LinearGradient(
  begin: Alignment.topLeft, // 渐变的开始位置，左边
  end: Alignment.bottomRight, // 渐变的结束位置，右边
  colors: [
    Color_left, // 起始颜色
    Color_right, // 结束颜色
  ],
);

// 保存字符串
Future<void> saveString(String key, String value) async {
  final prefs = await SharedPreferences.getInstance();
  await prefs.setString(key, value);
}

// 获取字符串
Future<String?> getString(String key) async {
  final prefs = await SharedPreferences.getInstance();
  return prefs.getString(key);
}

class GlobalConfig {
  static double scaleH = 0.0;
}

class assets {
  static const String _basePath = 'assets/images/';

  static String getImagePath(String imageName) {
    return '$_basePath$imageName.png';
  }

  // 定义具体的图片资源
  static const String batter_animation = '${_basePath}batter_animation.png';
  static const String batter = '${_basePath}batter.png';
  static const String bg = '${_basePath}bg.png';
  static const String ble_off = '${_basePath}ble_off.png';
  static const String ble_on = '${_basePath}ble_on.png';
  static const String icon = '${_basePath}icon.png';
  static const String logo = '${_basePath}logo.png';

  ///读取本地文件
  static Future<Uint8List?> readBinFile(String fileName) async {
    try {
      // 读取 bin 文件
      ByteData data = await rootBundle.load('assets/$fileName');

      // 将 ByteData 转换为 Uint8List 并返回
      return data.buffer.asUint8List();
    } catch (e) {
      print('Error reading bin file: $e');
      return null;
    }
  }
}
